package com.qing.picture.manager;

import com.aliyun.oss.OSS;
import com.aliyun.oss.model.PutObjectRequest;
import com.aliyun.oss.model.PutObjectResult;
import com.aliyun.oss.model.VoidResult;
import com.qing.picture.config.AliOssConfig;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.io.File;

@Component
public class CosManager {
    @Resource
    private AliOssConfig aliOssConfig;

    @Resource
    private OSS cosClient;

    /**
     * 上传对象
     *
     * @param key  唯一键
     * @param file 文件
     */
    public PutObjectResult putObject(String key, File file) {
        PutObjectRequest putObjectRequest = new PutObjectRequest(aliOssConfig.getBucketName(), key,
                file);
        return cosClient.putObject(putObjectRequest);
    }
    /**
     * 上传对象
     *
     * @param key  唯一键
     */
    public VoidResult deleteObject(String key) {
        return cosClient.deleteObject(aliOssConfig.getBucketName(),key);
    }
}
